home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / gs3.53 / rollconv.ps < prev    next >
Text File  |  1996-01-10  |  12KB  |  369 lines

  1. %!
  2. % Copyright (C) 1995 Aladdin Enterprises.  All rights reserved.
  3. %
  4. % rollconv.ps
  5. % Utility program for converting Japanese fonts produced by Macromedia's
  6. % Rollup program to Type 0 fonts suitable for use with Ghostscript.
  7. %
  8. % Rollup produces the following files, where xxx is the font name:
  9. %    xxx-H, xxx-SA, xxx-SB, xxx-SK, xxx-SR, xxx-UG
  10. %    JIS83-1_COD
  11. %    JIS83-1_CSA
  12. % The _COD and _CSA files are large files containing the actual
  13. % character outline data; they may theoretically be shared between
  14. % multiple fonts.
  15. %
  16. % rollconv.ps converts the above to files named:
  17. %    fff.ps
  18. %    fff.COD
  19. %    fff.CSA
  20. % where fff is a font file name provided by the user at conversion time.
  21. % The fff.ps file is the actual font file to be loaded with `run'
  22. % or placed in a Fontmap or a directory named by [GS_]FONTPATH;
  23. % the other two files must be present at runtime in a directory that is
  24. % on Ghostscript's search path (-I, GS_LIB, GS_LIB_DEFAULT).
  25. %
  26. % The normal way to invoke this program is
  27. %    gsnd -- rollconv.ps xxx fff InDir CDir OutDir
  28. % (assuming that gsnd is an alias for gs -dNODISPLAY), where:
  29. %    xxx is the font name;
  30. %    fff is the base part of the output file name;
  31. %    InDir is the name of the directory containing the xxx-* input files;
  32. %    CDir is the name of the directory containing the _COD and _CSA
  33. %      input files (typically the same as InDir);
  34. %    OutDir is the name of the directory where the output should be written
  35. %      (OutDir must already exist).
  36. % For example:
  37. %    gsnd -- rollconv.ps HGGothicBPRO gothic /gs/k/vid/fonts/Gothic \
  38. %      /gs/k/vid/fonts/Gothic /gs/k/vid/gsfonts
  39. % To suppress output messages, you may insert -q:
  40. %    gsnd -q -- rollconv.ps ...
  41. %
  42. % This program assumes that the files have been FTP'ed from a Macintosh and
  43. % therefore have 128 bytes of garbage at the beginning.  If you have
  44. % transferred them in some manner that avoids this, change true to false
  45. % in the following line.
  46. /fromMac true def
  47. % The FontName of the converted font is xxx-83pv-RKSJ-H.  In order to
  48. % use a converted font with Ghostscript, you may either load it explicitly
  49. % at run time, e.g.,
  50. %    (gothic.ps) run
  51. % or you may add an entry to the Fontmap file, in the form:
  52. %    /HGGothicBPRO-83pv-RKSJ-H  (gothic.ps)  ;
  53. % which will allow the font to be loaded automatically.  After
  54. % loading the font, by either method, you can select it in the usual way:
  55. %    /HGGothicBPRO-83pv-RKSJ-H findfont 36 scalefont setfont
  56. % or
  57. %    /HGGothicBPRO-83pv-RKSJ-H 36 selectfont
  58.  
  59.  
  60. /macrfile        % <filename> macrfile <file>
  61.  { (r) file
  62.    fromMac
  63.     {        % Get rid of the initial Mac garbage (128 characters).
  64.         % The garbage at the end is unpredictable,
  65.         % so we'll just have to hope that it's all nulls.
  66.       dup =string 0 128 getinterval readstring pop pop
  67.     }
  68.    if
  69.  } bind def
  70.  
  71. /convert        % <FName> <OutBase> <InDir> <CDir> <OutDir> convert -
  72.  { /OutDir exch def
  73.    /CDir exch def
  74.    /InDir exch def
  75.    /OutBase exch def
  76.    /FName exch def
  77.  
  78.    /inprefix InDir (/) concatstrings FName concatstrings (-) concatstrings def
  79.    /inh inprefix (H) concatstrings def
  80.  
  81.         % Open the output file.
  82.  
  83. /OutDot OutDir (/) concatstrings OutBase concatstrings (.) concatstrings def
  84. /outname OutDot (ps) concatstrings def
  85. QUIET not { (Writing ) print outname = flush } if
  86. /cdfromstr (\(pgfonts/) FName concatstrings (-JIS83-1_) concatstrings def
  87. /cdstr (\() OutBase concatstrings (.) concatstrings def
  88. /out outname (w) file def
  89. /buffer 65000 string def
  90.  
  91.         % Copy the initial comments from the input file.
  92.  
  93. inh macrfile
  94.  { dup =string readline pop
  95.    out 1 index writestring out (\n) writestring
  96.    (%%EndComments) eq { exit } if
  97.  }
  98. loop
  99.  
  100.         % Write out our preamble.
  101.  
  102. out (
  103. currentpacking true setpacking
  104. userdict /AltsysCFD3 known { (%END) .skipeof } if
  105. userdict /AltsysCFD3 25 dict dup begin
  106. /beint { 0 exch { exch 8 bitshift add } forall } bind def
  107. /rfile { findlibfile { exch pop } { (r) file } ifelse } bind def
  108. /str 500 string def
  109. /AltRO { } def
  110. /BuildCh        % <font> <ccode> <bias> BuildCh -
  111.  { /bias exch def  /ccode exch def  begin % font
  112.    ccode dup 255 and dup bias lt exch 252 gt or { pop 127 } if
  113.    dup -8 bitshift -67 mul add % subfonts have 189 chars, not 256
  114.    bias sub buildch1
  115.  } bind def
  116. /BuildChr        % <font> <ccode> BuildChr -
  117.  { /ccode exch def  begin % font
  118.    ccode buildch1
  119.  } bind def
  120. /buildch1
  121.  { 6 mul PGOffsets add
  122.    FileNames 0 get rfile dup dup 4 -1 roll setfileposition
  123.    (xxxxxx) readstring pop exch closefile
  124.    dup 1 3 getinterval beint % COD offset
  125.    exch 4 2 getinterval beint % length
  126.    dup 0 eq
  127.     { pop pop currentdict end
  128.       1000 0 0 0 1 1 0 -1000 500 1000 setcachedevice2
  129.     }
  130.     { dup str length gt { /str 1 index string store } if
  131.       FileNames 1 get rfile dup dup % offset length file file file
  132.       5 -1 roll setfileposition % length file file
  133.       str 0 5 -1 roll getinterval readstring pop pop closefile
  134.       currentdict end ccode str 1183615869 internaldict /CCRun get exec
  135.     }
  136.    ifelse
  137.  } bind def
  138. /privates 100 dict def
  139. /BuildPr        % <stdhw> <stdvw> BuildPr <dict>
  140.  { 2 copy 1000 mul add privates 1 index known
  141.     { privates exch get 3 1 roll pop pop
  142.     }
  143.     { 7 dict begin
  144.     /MinFeature{16 16}executeonly def
  145.     /BlueValues BlueValues def
  146.     /StdVW 3 -1 roll 1 array astore def
  147.     /StdHW 3 -1 roll 1 array astore def
  148.     /password 5839 def
  149.     /LanguageGroup 1 def
  150.     /Subrs Subrs def
  151.       currentdict readonly end
  152.       privates 2 index 2 index put exch pop
  153.     }
  154.    ifelse
  155.  } bind def
  156. /FullEncoding
  157.   systemdict { pop } forall
  158.   systemdict length 512 sub 1 255 { (x) dup 0 4 -1 roll put cvn } for
  159. 768 packedarray def
  160. /BlueValues[-250 -250 1100 1100]readonly def
  161. /BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def
  162. /CharStrings 1 dict
  163. dup /.notdef (┐1py╩8Åσ) noaccess put
  164. readonly def
  165. /CDevProc
  166.  { pop pop pop pop 0 exch -1000 exch 2 div currentfont /FontBBox get 3 get
  167.  } bind def
  168. /FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]readonly def
  169. /Subrs [
  170. (┐1p|=-ôD\ΓR) noaccess
  171. (┐1py╝÷Uz) noaccess
  172. (┐1py╜─₧i) noaccess
  173. (┐1p∙) noaccess
  174. (┐1p|35r╖I) noaccess
  175. ] noaccess def
  176. end put
  177. %END
  178. ) writestring
  179.  
  180.         % Locate and copy the definition of NotDefFont.
  181.  
  182. out (
  183. FontDirectory /NotDefFont known { (%END) .skipeof } if
  184. ) writestring
  185.  { dup =string readline pop
  186.    dup (/NotDefFont) eq { exit } if pop
  187.  }
  188. loop out exch writestring out (\n) writestring
  189.  { dup =string readline pop
  190.    (definefont) search { pop pop pop exit } if
  191.    out exch writestring out (\n) writestring
  192.  }
  193. loop out (definefont
  194. %END
  195. ) writestring
  196.  
  197.         % Copy the definitions of the subfonts, moving the
  198.         % CharStrings of the Roman supplement to an external file.
  199.         % Stack for pattern procedures: infile line
  200.  
  201. /CSRName OutDot (CSR) concatstrings def
  202. /csr CSRName (w) file def
  203. QUIET not { (Writing ) print CSRName = flush } if
  204.  
  205. /encoding 256 array def
  206.  
  207. /patterns [
  208.         % Patterns specific to the Roman supplement, in which
  209.         % the outlines are in an eexec section.
  210.  { (/Encoding 256 array) {
  211.    pop out (/Encoding ) writestring
  212.     { dup buffer readline pop
  213.       dup (dup) search { exit } if pop pop
  214.     }
  215.    loop
  216.     {    % Stack: infile dupline postdup (dup) predup
  217.       pop pop exch pop
  218.     % The top element of the stack is a string beginning with
  219.     % an index and value to put into the Encoding.
  220.       token pop exch token pop exch pop encoding 3 1 roll put
  221.       dup buffer readline pop
  222.       dup (dup) search not { pop exit } if
  223.     }
  224.    loop
  225.    out encoding cvx write== out ( cvlit ) writestring
  226.    out exch writestring out (\n) writestring
  227.  } }
  228.  { (/FontType 1 def) {
  229.    pop out (/FontType 4 def\n) writestring
  230.    out (/BuildChar{AltsysCFD3 begin BuildChr end}bind def\n) writestring
  231.    out (/FileNames[) writestring
  232.    2 { out OutBase (.CSR) concatstrings write==only } repeat
  233.    out (]def\n) writestring
  234.  } }
  235.  { (currentfile eexec) {
  236.    pop out (systemdict begin\n) writestring
  237.    dup 55665 /eexecDecode filter
  238.  } }
  239.  { (dup/CharStrings ) {
  240.     % Copy the individual CharStrings to the CSR file,
  241.     % recording the lengths and offsets.
  242.    pop out (dup/CharStrings AltsysCFD3 /CharStrings get put\n) writestring
  243.    /offsets 256 dict def
  244.     { dup token pop        % char name
  245.       dup dup type /nametype eq exch xcheck not and not { pop exit } if
  246.       1 index token pop        % length of binary data
  247.       2 index token pop pop    % skip RD
  248.       2 index buffer 0 3 index getinterval readstring pop    % charstring
  249.       offsets 3 index csr fileposition 16 bitshift 4 index add put
  250.       csr exch writestring pop pop
  251.       dup buffer readline pop pop    % skip ND
  252.     }
  253.    loop
  254.     % We skipped the 'end'; skip the 'readonly put' as well.
  255.    2 { dup token pop pop } repeat
  256.    out (dup/PGOffsets ) writestring
  257.      out csr fileposition write=only
  258.      out ( put\n) writestring
  259.    encoding
  260.     { offsets exch .knownget not { 0 } if
  261.       2 { csr 0 write } repeat
  262.       4 { dup -24 bitshift csr exch write 8 bitshift } repeat pop
  263.     }
  264.    forall
  265.  } }
  266.  { (/OtherSubrs[) {
  267.    pop
  268.     { dup buffer readline pop
  269.       (]noaccess def) search { pop pop pop exit } if pop
  270.     }
  271.    loop
  272.  } }
  273.  { (/Subrs 5 array) {
  274.    pop out (/Subrs AltsysCFD3 /Subrs get def\n) writestring
  275.    6 { dup buffer readline pop pop } repeat
  276.  } }
  277.  { (currentfile closefile) {
  278.    pop out (end % systemdict\n) writestring
  279.    closefile
  280.  } }
  281.         % Patterns for other supplements.
  282.  { (pgfonts/) {
  283.     { cdfromstr search not { exit } if
  284.       out exch writestring pop out cdstr writestring
  285.     }
  286.    loop out exch writestring out (\n) writestring
  287.  } }
  288.  { (/BuildChar{AltsysCFD3 begin 64 BuildCh end}bind def) {
  289.    pop out (\t/BuildChar AltsysCFD3 /BuildChar get def\n) writestring
  290.  } }
  291.  { (/CDevProc{pop pop pop pop 0 exch -1000 exch 2 div ) {
  292.    pop out (\t/CDevProc AltsysCFD3 /CDevProc get def\n) writestring
  293.  } }
  294.  { (/CharStrings 1 dict dup begin) {
  295.    pop out (\t/CharStrings AltsysCFD3 /CharStrings get def\n) writestring
  296.    2 { dup buffer readline pop pop } repeat
  297.  } }
  298.  { (/FontMatrix[0.001 0.0 0.0 0.001 0.0 0.0]def) {
  299.    pop out (\t/FontMatrix AltsysCFD3 /FontMatrix get def\n) writestring
  300.  } }
  301.  { (/Private 14 dict dup begin) {
  302.    pop out (\t/Private) writestring
  303.     { dup buffer readline pop
  304.       (end def) search { pop pop pop exit } if
  305.       (/Std) search
  306.        { pop pop dup length 3 sub 3 exch getinterval
  307.      (]) search pop out ( ) writestring out exch writestring pop
  308.        }
  309.       if pop
  310.     }
  311.    loop out ( AltsysCFD3 begin BuildPr end def\n) writestring
  312.  } }
  313.  { (UniqueID) { pop } }
  314.  { () {
  315.    out exch writestring out (\n) writestring
  316.  } }
  317. ] def
  318. [ (SR) (SA) (SK) (SB) (UG) ]
  319.  { 0 1 255 { encoding exch /.notdef put } for
  320.    inprefix exch concatstrings macrfile
  321.     { dup buffer readline not { pop exit } if
  322.       /patterns load
  323.        { 2 copy 0 get search { pop pop pop 1 get exec exit } if pop pop }
  324.       forall
  325.     }
  326.    loop closefile
  327.  }
  328. forall
  329. csr closefile
  330.  
  331.         % Copy the definition of the root font.
  332.  
  333. dup buffer readstring pop out exch writestring closefile
  334. out closefile
  335.  
  336.         % Remove the Mac garbage from the outline files.
  337.  
  338. [ (COD) (CSA) ]
  339.  { CDir (/) concatstrings (JIS83-1_) concatstrings
  340.      1 index concatstrings macrfile
  341.    exch OutDot exch concatstrings
  342.      QUIET not { (Writing ) print dup = flush } if
  343.      (w) file
  344.         % Stack: infile outfile
  345.     { 1 index buffer readstring exch
  346.         % Stack: infile outfile noteof substring
  347.       2 index exch writestring not { exit } if
  348.     }
  349.    loop closefile closefile
  350.  }
  351. forall
  352.  
  353.  } bind def
  354.  
  355. % If the program was invoked from the command line, run it now.
  356. [ shellarguments
  357.  { counttomark 5 eq
  358.     { convert
  359.       QUIET not { (Done.\n) print flush } if
  360.     }
  361.     { cleartomark
  362.       (Usage: gsnd -- rollconv.ps FName OutBase InDir CDir OutDir\n) print
  363.       ( e.g.: gsnd -- rollconv.ps HGMinchoE mincho HGfonts/Mincho HGfonts/Mincho HGfonts/gs\n) print flush
  364.       mark
  365.     }
  366.    ifelse
  367.  }
  368. if pop
  369.